﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;

namespace DigitalSolutionLibrary.SqlDatabase
{
    public class ParameterStock
    {
        private List<Parameter> lstParam;

        /// <summary>
        /// Create new stock to save Parameter
        /// </summary>
        public ParameterStock()
        {
            lstParam = new List<Parameter>();
        }

        /// <summary>
        /// Add Parameter for stock
        /// </summary>
        /// <param name="parameter"></param>
        public void AddParamter(Parameter parameter)
        {
            lstParam.Add(parameter);
        }

        /// <summary>
        /// Get array of Parameter in stock
        /// </summary>
        /// <returns>Array SqlParameter</returns>
        public SqlParameter[] GetArrayParameter()
        {
            SqlParameter[] array = new SqlParameter[lstParam.Count];
            for (int i = 0; i < lstParam.Count; i++)
                array[i] = lstParam[i].GetParameter();

            return array;
        }

        public Parameter GetAtPosition(int position)
        {
            if (position >= lstParam.Count)
                return null;
            else
                return lstParam[position];
        }

        public Parameter GetByName(string name)
        {
            foreach (Parameter par in lstParam)
            {
                if (par.GetParameter().ParameterName == name)
                    return par;
            }
            return null;
        }
    }
}
